package cn.hchaojie.blog.web;

import java.io.IOException;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSON;

import cn.hchaojie.blog.domain.Post;

public class PostServlet extends HttpServlet {
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		String parameter = req.getParameter("id");
		System.out.println(parameter);
		
		Post post = new Post();
		post.setId(1);
		post.setTitle("java大法好");
		post.setContent("java是最好的语言");
		post.setCreated(new Date());
		
		String string = JSON.toJSONString(post);
		System.out.println(string);
		
		resp.setContentType("application/json;charset=utf-8");
		
		resp.getWriter().write(string);
	}
}
